package com.dk.localdate;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class LocalDateTest {
    public static void main(String[] args) {
        LocalDateTime l = LocalDateTime.now();
        System.out.println(l);
        LocalDateTime l2 = LocalDateTime.of(2021,12,24,15,43,12);
        System.out.println(l2);
        LocalDateTime minusDays = l.minusDays(8);
        System.out.println(minusDays);
        System.out.println(minusDays.getDayOfMonth());
        System.out.println(minusDays.getDayOfWeek().getValue());
        LocalDateTime localDateTime = l.plusDays(8);
        System.out.println(localDateTime);

        //数据库查询的日期转成localdatetime类型
        Date date = new Date();
        LocalDateTime localDateTime1 = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        System.out.println(localDateTime1);
        //localdatetime转成Date类型
        Date from = Date.from(localDateTime1.atZone(ZoneId.systemDefault()).toInstant());
        System.out.println(from);
    }
}
